package com.andyyan.ai.chatbot.service.impl;

import com.andyyan.ai.chatbot.mapper.ConversationMapper;
import com.andyyan.ai.chatbot.model.Conversation;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.UUID;

/**
 * 暂时无需定义接口
 */
@RequiredArgsConstructor
@Service("conversationService")
public class ConversationServiceImpl {
    private final ConversationMapper conversationMapper;

    public List<Conversation> userConversationList(String userId) {
        return conversationMapper.userConversationList(userId);
    }

    public Conversation createConversation(String userId) {
        String conversationId = UUID.randomUUID().toString();
        Conversation conversation = new Conversation();
        conversation.setUserId(userId);
        conversation.setConversationId(conversationId);
        conversation.setName(conversationId.substring(0, 5));

        int result = conversationMapper.insert(conversation);
        return result > 0 ? conversation : null;
    }

    public boolean deleteConversation(String userId, String conversationId) {
        int result = conversationMapper.delete(userId, conversationId);
        return result > 0;
    }

    public Conversation queryConversation(String userId, String conversationId) {
        return conversationMapper.queryConversation(userId, conversationId);
    }
}
